package com.ftg.learn.order.controller;

import com.ftg.learn.common.result.PageResult;
import com.ftg.learn.common.result.Result;
import com.ftg.learn.order.dto.OrderDto;
import com.ftg.learn.order.dto.PageQueryDto;
import com.ftg.learn.order.dto.payDto;
import com.ftg.learn.order.entity.OrderDetail;
import com.ftg.learn.order.service.OrderDetailService;
import com.ftg.learn.order.service.OrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/order")
@Tag(name = "订单相关接口")
@RequiredArgsConstructor
public class OrderController {
    @Autowired
    private OrderService orderService;
    @Autowired
    private OrderDetailService orderDetailService;

    @GetMapping("page")
    @Operation(summary = "分页查询")
    public Result<PageResult> page(@RequestBody PageQueryDto queryDto){
        return orderService.pageQuery(queryDto);
    }
    @GetMapping
    @Operation(summary = "查询订单详情")
    public Result<List<OrderDetail>> getOrderDetail(@RequestParam("orderId") String orderId){
        return orderDetailService.getOrderDetail(orderId);
    }
    @PostMapping
    @Operation(summary = "创建订单")
    public Result<String> createOrder(@RequestBody OrderDto orderDto){
        return orderService.createOrder(orderDto);
    }
    @PostMapping("/add")
    @Operation(summary = "添加订单")
    public Result<String> addOrder(@RequestParam("orderId") String orderId){
        return orderService.addOrder(orderId);
    }
    //支付订单
    @PostMapping("/pay")
    @Operation(summary = "支付订单")
    public Result<String> payOrder(@RequestBody payDto payDto){
        return orderService.payOrder(payDto);
    }
    //删除订单
    @DeleteMapping
    @Operation(summary = "删除订单")
    public Result<String> deleteOrder(@RequestParam("orderId") String orderId){
        return orderService.deledeById(orderId);
    }

}
